﻿using MedicalManagementAPP.AccountModule;
using MedicalManagementAPP.Forms;
using MedicalManagementAPP.MyException;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MedicalManagementAPP
{
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            InitializeComponent();
            skinEngine1.SkinFile = @"irisskin2\Wave.ssk";
        }

        private void LoginButton_Click(object sender, EventArgs e)
        {
            string name = accountTextBox.Text;
            string psw = pswTextBox.Text;
            string type = comboBox1.Text;
            Person person;

            if (name=="" || psw == "" || type == "")
            {
                MessageBox.Show("所有信息都需要输入");
                return;
            }
            try
            {
                person = AccountManager.Login(name, psw, type);
            }
            catch (PersonNotFound)
            {
                MessageBox.Show("账号不存在\n请检查用户类型");
                Clear();
                return;
            }
            catch (WrongPassword)
            {
                MessageBox.Show("账号或密码或用户类型输入错误\n请检查输入");
                Clear();
                return;
            }
            switch (person.PType)
            {
                case "Patient":
                    new PatientForm(this, person).Show();
                    break;
                case "Worker":
                    new DocForm(this, person).Show();
                    break;
                case "Admin":
                    new AdminForm(this, person).Show();
                    break;
            }
            this.Hide();
            Clear();
        }

        private void RegButton_Click(object sender, EventArgs e)
        {
            new RegForm(this).Show();
            this.Hide();
        }
        private void Clear()
        {
            pswTextBox.Clear();
            accountTextBox.Clear();
        }
    }
}
